import java.util.ArrayList;
import java.util.List;

/**
* @description: 1656. 设计有序流
* @author hewei
* @date 2022/8/16 15:26
* @version 1.0
*/

public class OrderedStream {

    int ptr;
    String[] temp;
    int n;
    public OrderedStream(int n) {
        this.n = n;
        ptr = 1;
        temp = new String[n + 1];
    }

    public List<String> insert(int idKey, String value) {
        temp[idKey] = value;
        List<String> list = new ArrayList<>();
        if (temp[ptr] == null) return list;
        while (ptr < temp.length) {
            if (temp[ptr] == null) break;
            list.add(temp[ptr]);
            temp[ptr++] = null;
        }
        return list;
    }
}
